//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "init_common.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE("start");

GVAR(current_world) = toLower(getText (configFile>>"CfgWorlds">>worldName>> "worldname"));
GVAR(current_world_name) = "World";
switch (GVAR(current_world)) do {
	case "\a3\map_stratis\stratis.wrp": { GVAR(current_world_name) = "Stratis";	};
	case "\a3\map_altis\altis.wrp": { GVAR(current_world_name) = "Altis";	};
	case "kerama\kerama.wrp": { GVAR(current_world_name) = "Kerama";	};
	case "\veterans\angel\angel.wrp": { GVAR(current_world_name) = "Angel Island";	};
};
DEBUG_1("Current World",[GVAR(current_world), GVAR(current_world_name)]);

TLOG("Add the handling of the CreateCenter logic");
// createCenter east;
// createCenter west;
// createCenter Resistance;
// createCenter civilian;
// createCenter sideLogic;

CHK_STRING(GVAR(own_side),"");

// Auto-evaluate player side if not set
if (isNil QGVAR(own_side) || {GVAR(own_side) == ""}) then {
	_side_players = GVAR(own_side);
	_side_unit = "";
	_sides = [];
	if (GVAR(MP)) then {
		{
			_side_unit = str (side _x);
			if ((_sides find _side_unit) < 0) then {
				_sides set[count _sides, _side_unit];
			};
		} foreach playableUnits;
		if (count _sides == 1) then {
			_side_players = _sides select 0;
		};
	} else {
		_side_players = str (side player);
	};
	GVAR(own_side) = _side_players;

	GVAR(own_side) = switch(toupper(GVAR(own_side))) do {
				case "WEST":{"WEST"};
				case "EAST":{"EAST"};
				case "GUER":{"GUER"};
				case "RESISTANCE":{"GUER"};
				default{"WEST"};
	};
};
TLOG_1("Players Side", GVAR(own_side));

GVAR(side_own) = switch(GVAR(own_side)) do {
			case "WEST":{west};
			case "EAST":{east};
			case "GUER":{resistance};
			default { west };
};

GVAR(enemy_side) = switch(toupper(GVAR(own_side))) do {
			case "WEST":{
				if ((west getFriend east) < 0.6) then {
					"EAST"
				} else {
					"GUER"
				};
			};
			case "EAST":{
				if ((east getFriend west) < 0.6) then {
					"WEST"
				} else {
					"GUER"
				};
			};
			case "GUER":{
				if ((resistance getFriend west) < 0.6) then {
					"WEST"
				} else {
					"EAST"
				};
			};
			default{"EAST"};
};
GVAR(side_enemy) = switch(GVAR(enemy_side)) do {
			case "WEST":{west};
			case "EAST":{east};
			case "GUER":{resistance};
			default { east };
};
TRACE_1("Enemy Side", GVAR(enemy_side));

GVAR(friendly_guerilla) = switch (GVAR(own_side)) do {
			case "WEST":{
				if ((west getFriend resistance) < 0.6) then {
					false
				} else {
					true
				};
			};
			case "EAST":{
				if ((east getFriend resistance) < 0.6) then {
					false
				} else {
					true
				};
			};
			default {
				true
			};
};

TRACE("Executed");